package com.jyq.jsp.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.zip.GZIPOutputStream;

/**
 * @author Jiang Yongqiang
 */
@WebServlet(name = "GZIPServlet",urlPatterns = "/gzip.html")
public class GZIPServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        GZIPOutputStream outputStream = new GZIPOutputStream(response.getOutputStream());
        ServletOutputStream outputStream = response.getOutputStream();
        PrintWriter printWriter = new PrintWriter(outputStream);
        response.sendError(HttpServletResponse.SC_BAD_GATEWAY,"网关错误");
        printWriter.println("this is gzip!");
        printWriter.flush();
        printWriter.close();
    }
}
